﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MovieModels;

namespace MK_Movie_Manager
{
    public partial class ImageSearchResultComponent : UserControl
    {
        public ImageSearchResultComponent(IEnumerable<BingImageSearchResult> results)
        {
            InitializeComponent();
            for (int i = 0; i < results.Count(); i++)
            {
                var rpb=InitializePictureBox(i, results.ElementAt(i));
                this.Controls.Add(rpb);
            }
            //this.Controls.Add(curGB);
        }

        private void ImageSearchResultComponent_Load(object sender, EventArgs e)
        {

        }
        private Panel InitializePictureBox(int imgSerial,BingImageSearchResult res)
        {
            int rowno = imgSerial / 4;
            int colno = imgSerial % 4;
            int rowspacing = 9;
            int colspacing = 19;
            int rowwidth = 167;
            int colwidth = 146;

            Panel curImgPanel = new Panel();

            RadioButton curRadioButton = new RadioButton();
            curRadioButton.AutoSize = true;
            curRadioButton.Location = new System.Drawing.Point(15, 142);
            curRadioButton.Name = "radioButton1";
            curRadioButton.Size = new System.Drawing.Size(85, 30);
            curRadioButton.TabIndex = 1;
            curRadioButton.TabStop = true;
            curRadioButton.Text = res.Title.Replace("Photos from","");
            curRadioButton.UseVisualStyleBackColor = true;


            PictureBox curPicBox = new PictureBox();
            curPicBox.Location = new System.Drawing.Point(3, 3);
            curPicBox.Name = "pictureBox1";
            curPicBox.Size = new System.Drawing.Size(140, 133);
            curPicBox.ImageLocation = res.ThumbNailURL;
            curPicBox.TabStop = false;
            

            curImgPanel.Controls.Add(curRadioButton);
            curImgPanel.Controls.Add(curPicBox);
            curImgPanel.Location = new System.Drawing.Point(11+colno*(colspacing+colwidth), 11+rowno*(rowspacing+rowwidth));
            curImgPanel.Name = "panel1";
            curImgPanel.Size = new System.Drawing.Size(146, 167);
            curImgPanel.TabIndex = 0;
            return curImgPanel;
        }

    }
}
